﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using BarCode.Common;

namespace LackCodePrint
{

    public class LackCodePrint
    {
        public static void PrtBarCode2S(PrintInfo printInfo)
        {
            int xStart, yStart, xDist, yDist, fontDist;
            int fontsize;

            xStart = 20 + printInfo.intDist;
            yStart = 50;
            xDist = 375;
            yDist = 90;
            if (String.IsNullOrEmpty(printInfo.extral))
            {
                fontDist = 10;
            }
            else
            {
                fontDist = 0;
            }
            
            fontsize = 45;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("60", "13", "2", "13", "0", "2.8", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "90", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0] + printInfo.extral);

            TSCLIB_DLL.barcode(Convert.ToString(xStart + xDist), Convert.ToString(yStart), "128", "90", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[1]);
            TSCLIB_DLL.windowsfont((xStart + fontDist + xDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[1] + printInfo.extral);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();
        }


        public static void PrtBarCode2SWithChar(PrintInfo printInfo)
        {
            int xStart, yStart, xDist, yDist, fontDist;
            int fontsize;

            xStart = 50 + printInfo.intDist;
            yStart = 50;
            xDist = 375;
            yDist = 90;
            fontDist = -20;
            if (printInfo.strCode[0].Length == 11)
            {
                fontDist = 5;
            }
            else if (printInfo.strCode[0].Length == 12)
            {
                fontDist = -20;
            }
            else if (printInfo.strCode[0].Length == 13)
            {
                fontDist = -35;
            }

            fontsize = 45;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("60", "13", "2", "13", "0", "2.8", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "90", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0] + printInfo.extral);

            TSCLIB_DLL.barcode(Convert.ToString(xStart + xDist), Convert.ToString(yStart), "128", "90", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[1]);
            TSCLIB_DLL.windowsfont((xStart + fontDist + xDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[1] + printInfo.extral);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();
        }

        public static void PrtBarCode2L(PrintInfo printInfo)
        {
            int xStart, yStart, xDist, yDist, fontDist;
            int fontsize;

            xStart = 0 + printInfo.intDist;
            yStart = 0;
            xDist = 560;
            yDist = 75;
            fontDist = 40;
            fontsize = 50;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("90", "11", "2", "13", "0", "2.8", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "80", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0]);

            TSCLIB_DLL.barcode(Convert.ToString(xStart + xDist), Convert.ToString(yStart), "128", "80", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[1]);
            TSCLIB_DLL.windowsfont((xStart + fontDist + xDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[1]);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();

        }

        public static void PrtBarCode1AS17(PrintInfo printInfo)
        {
            int xStart, yStart, yDist, fontDist;
            int fontsize;

            xStart = 65 + printInfo.intDist;
            yStart = 24;
            yDist = 120;
            fontDist = 35;
            fontsize = 55;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("60", "15", "2", "13", "0", "2.8", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "120", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0]);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();
        }

        public static void PrtBarCode1AS10(PrintInfo printInfo)
        {
            int xStart, yStart, yDist, fontDist;
            int fontsize;

            xStart = 75 + printInfo.intDist;
            yStart = 24;
            yDist = 120;
            fontDist = 140;
            fontsize = 55;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("60", "15", "2", "13", "0", "2.8", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "120", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0]);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();
        }














        public static void PrtBarCodeS(PrintInfo printInfo)
        {
            int xStart, yStart, xDist, yDist, fontDist;
            int fontsize;

            xStart = 20 + printInfo.intDist;
            yStart = 20;
            xDist = 375;
            yDist = 85;
            fontDist = -10;
            fontsize = 40;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("60", "13", "2", "13", "0", "2.8", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "90", "0", "0", "3", "4", printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0]);

            TSCLIB_DLL.barcode(Convert.ToString(xStart + xDist), Convert.ToString(yStart), "128", "90", "0", "0", "3", "4", printInfo.strCode[1]);
            TSCLIB_DLL.windowsfont((xStart + fontDist + xDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[1]);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();

        }

        public static void PrtBarCodeNS(PrintInfo printInfo)
        {
            int xStart, yStart, xDist, yDist, fontDist, fontsize;

            xStart = 20 + printInfo.intDist;
            yStart = 0;
            xDist = 375;
            yDist = 90;
            fontDist = -10;
            fontsize = 52;

            TSCLIB_DLL.openport(GlobalVal.PrinterName);
            TSCLIB_DLL.setup("62", "13", "2", "13", "0", "3", "0");
            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.barcode(Convert.ToString(xStart), Convert.ToString(yStart), "128", "90", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[0]);
            TSCLIB_DLL.windowsfont((xStart + fontDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[0]);

            TSCLIB_DLL.barcode(Convert.ToString(xStart + xDist), Convert.ToString(yStart), "128", "90", "0", "0", printInfo.narrow, printInfo.wide, printInfo.strCode[1]);
            TSCLIB_DLL.windowsfont((xStart + fontDist + xDist), (yStart + yDist), fontsize, 0, 2, 0, "黑体", printInfo.strCode[1]);

            TSCLIB_DLL.printlabel("1", "1");
            TSCLIB_DLL.closeport();

        }


    }
}
